﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using MockPrjTeam2.Common;

namespace MockPrjTeam2.DAO
{
    public class PremisesDao:Ketnoi
    {
        #region[Getall]
        public List<Entity.PremiseInfor> GetAll()
        {
            List<Entity.PremiseInfor> lst = new List<Entity.PremiseInfor>();
            using (SqlCommand cmd = new SqlCommand("sp_Premises_Getall", connect()))
            {
                Entity.PremiseInfor obj = new Entity.PremiseInfor();
                cmd.CommandType = CommandType.StoredProcedure;
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        lst.Add(obj.MappingEntity(dr));
                    }
                }
                dr.Close();
                obj = null;
            }
            return lst;
        }
        #endregion
        #region[GetByNameStartWith]
        public List<Entity.PremiseInfor> GetByNameStartWith(string startWith)
        {
            List<Entity.PremiseInfor> list = new List<Entity.PremiseInfor>();
            using (SqlCommand dbCmd = new SqlCommand("sp_Premises_stawith", connect()))
            {
                Entity.PremiseInfor obj = new Entity.PremiseInfor();
                dbCmd.CommandType = CommandType.StoredProcedure;
                dbCmd.Parameters.Add(new SqlParameter("@FirtName", startWith));
                SqlDataReader dr = dbCmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        list.Add(obj.MappingEntity(dr));
                    }
                }
                dr.Close();
                obj = null;
            }
            return list;
        }
        #endregion
        #region[Premise_delete]
        public bool Delete(string id)
        {
            using (SqlCommand cmd = new SqlCommand("sp_Premises_delete", connect()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@ProgrammeID", id));
                cmd.ExecuteNonQuery();
            }
            return true;
        }
        #endregion
        #region[update]
        public bool Update(Entity.PremiseInfor data)
        {
            using (SqlCommand cmd = new SqlCommand("sp_Premises_update", connect()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Accreditations", data.Accreditations));
                cmd.Parameters.Add(new SqlParameter("@AddressID", data.AddressID));
                cmd.Parameters.Add(new SqlParameter("@BBNegotiatedRate", data.BBNegotiatedRate));
                cmd.Parameters.Add(new SqlParameter("@BBRate", data.BBRate));
                cmd.Parameters.Add(new SqlParameter("@CateringTypeID", data.CateringTypeID));
                cmd.Parameters.Add(new SqlParameter("@CityTown", data.CityTown));
                cmd.Parameters.Add(new SqlParameter("@ClientITFacilitiesDetails", data.ClientITFacilitiesDetails));
                cmd.Parameters.Add(new SqlParameter("@Coding", data.Coding));
                cmd.Parameters.Add(new SqlParameter("@Comment", data.Comment));
                cmd.Parameters.Add(new SqlParameter("@ContacID", data.ContacID));
                cmd.Parameters.Add(new SqlParameter("@Country", data.Country));
                cmd.Parameters.Add(new SqlParameter("@CountryID", data.CountryID));
                cmd.Parameters.Add(new SqlParameter("@DBBNegotiatedRate", data.DBBNegotiatedRate));
                cmd.Parameters.Add(new SqlParameter("@DDRate", data.DDRate));
                cmd.Parameters.Add(new SqlParameter("@GeneralFaxNumber", data.GeneralFaxNumber));
                cmd.Parameters.Add(new SqlParameter("@hrNegotiatedRate", data.hrNegotiatedRate));
                cmd.Parameters.Add(new SqlParameter("@hrRate", data.hrRate));
                //cmd.Parameters.Add(new SqlParameter("@AddressID", data.IsActive));
                cmd.Parameters.Add(new SqlParameter("@IsNetwork", data.IsNetwork));
                cmd.Parameters.Add(new SqlParameter("@JSPOffices", data.JSPOffices));
                cmd.Parameters.Add(new SqlParameter("@LastNegotiatedDate", data.LastNegotiatedDate));
                cmd.Parameters.Add(new SqlParameter("@LocalDemographicIssues", data.LocalDemographicIssues));
                cmd.Parameters.Add(new SqlParameter("@LocalDemographicNotes", data.LocalDemographicNotes));
                cmd.Parameters.Add(new SqlParameter("@LocalHotels", data.LocalHotels));
                cmd.Parameters.Add(new SqlParameter("@LocationStatusDate", data.LocationStatusDate));
                cmd.Parameters.Add(new SqlParameter("@LocationStatusID", data.LocationStatusID));
                cmd.Parameters.Add(new SqlParameter("@LocationTypeDescription", data.LocationTypeDescription));
                cmd.Parameters.Add(new SqlParameter("@LocationTypeID", data.LocationTypeID));
                cmd.Parameters.Add(new SqlParameter("@Lunch", data.Lunch));
                cmd.Parameters.Add(new SqlParameter("@MeetingRoomRatePerDay", data.MeetingRoomRatePerDay));
                cmd.Parameters.Add(new SqlParameter("@MiniCommNumber", data.MiniCommNumber));
                cmd.Parameters.Add(new SqlParameter("@NegotiatedRoomOnlyRate", data.NegotiatedRoomOnlyRate));
                cmd.Parameters.Add(new SqlParameter("@NoOfMeetingRooms", data.NoOfMeetingRooms));
                cmd.Parameters.Add(new SqlParameter("@OrgID", data.OrgID));
                cmd.Parameters.Add(new SqlParameter("@OutreachLocation", data.OutreachLocation));
                cmd.Parameters.Add(new SqlParameter("@PhoneNumber", data.PhoneNumber));
                cmd.Parameters.Add(new SqlParameter("@PreferredStatus", data.PreferredStatus));
                cmd.Parameters.Add(new SqlParameter("@PremiseID", data.PremiseID));
                cmd.Parameters.Add(new SqlParameter("@ReNegotiatedOn", data.ReNegotiatedOn));
                cmd.Parameters.Add(new SqlParameter("@RoomAvailability", data.RoomAvailability));
                cmd.Parameters.Add(new SqlParameter("@RoomOnlyRate", data.RoomOnlyRate));
                cmd.Parameters.Add(new SqlParameter("@ShopFlagDate", data.ShopFlagDate));
                cmd.Parameters.Add(new SqlParameter("@SpecialistShop", data.SpecialistShop));
                cmd.Parameters.Add(new SqlParameter("@TeaCoffee", data.TeaCoffee));
                cmd.Parameters.Add(new SqlParameter("@TravelDetails", data.TravelDetails));
                cmd.Parameters.Add(new SqlParameter("@TravelNearesAirport", data.TravelNearesAirport));
                cmd.Parameters.Add(new SqlParameter("@TravelNearestBus", data.TravelNearestBus));
                cmd.Parameters.Add(new SqlParameter("@TravelNearestRail", data.TravelNearestRail));
                cmd.Parameters.Add(new SqlParameter("@VisitorParkingAlternative", data.VisitorParkingAlternative));
                cmd.Parameters.Add(new SqlParameter("@VisitorParkingOnsite", data.VisitorParkingOnsite));
                cmd.Parameters.Add(new SqlParameter("@VisitorParkingSpace", data.VisitorParkingSpace));
                cmd.Parameters.Add(new SqlParameter("@VolunteeringOpportunies", data.VolunteeringOpportunies));
                cmd.ExecuteNonQuery();
            }
            return true;
        }
        #endregion
        #region[insert]
        public bool Insert(Entity.PremiseInfor data)
        {
            using (SqlCommand cmd = new SqlCommand("sp_Premises_insert", connect()))
            {
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@Accreditations", data.Accreditations));
                cmd.Parameters.Add(new SqlParameter("@AddressID", data.AddressID));
                cmd.Parameters.Add(new SqlParameter("@BBNegotiatedRate", data.BBNegotiatedRate));
                cmd.Parameters.Add(new SqlParameter("@BBRate", data.BBRate));
                cmd.Parameters.Add(new SqlParameter("@CateringTypeID", data.CateringTypeID));
                cmd.Parameters.Add(new SqlParameter("@CityTown", data.CityTown));
                cmd.Parameters.Add(new SqlParameter("@ClientITFacilitiesDetails", data.ClientITFacilitiesDetails));
                cmd.Parameters.Add(new SqlParameter("@Coding", data.Coding));
                cmd.Parameters.Add(new SqlParameter("@Comment", data.Comment));
                cmd.Parameters.Add(new SqlParameter("@ContacID", data.ContacID));
                cmd.Parameters.Add(new SqlParameter("@Country", data.Country));
                cmd.Parameters.Add(new SqlParameter("@CountryID", data.CountryID));
                cmd.Parameters.Add(new SqlParameter("@DBBNegotiatedRate", data.DBBNegotiatedRate));
                cmd.Parameters.Add(new SqlParameter("@DDRate", data.DDRate));
                cmd.Parameters.Add(new SqlParameter("@GeneralFaxNumber", data.GeneralFaxNumber));
                cmd.Parameters.Add(new SqlParameter("@hrNegotiatedRate", data.hrNegotiatedRate));
                cmd.Parameters.Add(new SqlParameter("@hrRate", data.hrRate));
                //cmd.Parameters.Add(new SqlParameter("@AddressID", data.IsActive));
                cmd.Parameters.Add(new SqlParameter("@IsNetwork", data.IsNetwork));
                cmd.Parameters.Add(new SqlParameter("@JSPOffices", data.JSPOffices));
                cmd.Parameters.Add(new SqlParameter("@LastNegotiatedDate", data.LastNegotiatedDate));
                cmd.Parameters.Add(new SqlParameter("@LocalDemographicIssues", data.LocalDemographicIssues));
                cmd.Parameters.Add(new SqlParameter("@LocalDemographicNotes", data.LocalDemographicNotes));
                cmd.Parameters.Add(new SqlParameter("@LocalHotels", data.LocalHotels));
                cmd.Parameters.Add(new SqlParameter("@LocationStatusDate", data.LocationStatusDate));
                cmd.Parameters.Add(new SqlParameter("@LocationStatusID", data.LocationStatusID));
                cmd.Parameters.Add(new SqlParameter("@LocationTypeDescription", data.LocationTypeDescription));
                cmd.Parameters.Add(new SqlParameter("@LocationTypeID", data.LocationTypeID));
                cmd.Parameters.Add(new SqlParameter("@Lunch", data.Lunch));
                cmd.Parameters.Add(new SqlParameter("@MeetingRoomRatePerDay", data.MeetingRoomRatePerDay));
                cmd.Parameters.Add(new SqlParameter("@MiniCommNumber", data.MiniCommNumber));
                cmd.Parameters.Add(new SqlParameter("@NegotiatedRoomOnlyRate", data.NegotiatedRoomOnlyRate));
                cmd.Parameters.Add(new SqlParameter("@NoOfMeetingRooms", data.NoOfMeetingRooms));
                cmd.Parameters.Add(new SqlParameter("@OrgID", data.OrgID));
                cmd.Parameters.Add(new SqlParameter("@OutreachLocation", data.OutreachLocation));
                cmd.Parameters.Add(new SqlParameter("@PhoneNumber", data.PhoneNumber));
                cmd.Parameters.Add(new SqlParameter("@PreferredStatus", data.PreferredStatus));
                cmd.Parameters.Add(new SqlParameter("@PremiseID", data.PremiseID));
                cmd.Parameters.Add(new SqlParameter("@ReNegotiatedOn", data.ReNegotiatedOn));
                cmd.Parameters.Add(new SqlParameter("@RoomAvailability", data.RoomAvailability));
                cmd.Parameters.Add(new SqlParameter("@RoomOnlyRate", data.RoomOnlyRate));
                cmd.Parameters.Add(new SqlParameter("@ShopFlagDate", data.ShopFlagDate));
                cmd.Parameters.Add(new SqlParameter("@SpecialistShop", data.SpecialistShop));
                cmd.Parameters.Add(new SqlParameter("@TeaCoffee", data.TeaCoffee));
                cmd.Parameters.Add(new SqlParameter("@TravelDetails", data.TravelDetails));
                cmd.Parameters.Add(new SqlParameter("@TravelNearesAirport", data.TravelNearesAirport));
                cmd.Parameters.Add(new SqlParameter("@TravelNearestBus", data.TravelNearestBus));
                cmd.Parameters.Add(new SqlParameter("@TravelNearestRail", data.TravelNearestRail));
                cmd.Parameters.Add(new SqlParameter("@VisitorParkingAlternative", data.VisitorParkingAlternative));
                cmd.Parameters.Add(new SqlParameter("@VisitorParkingOnsite", data.VisitorParkingOnsite));
                cmd.Parameters.Add(new SqlParameter("@VisitorParkingSpace", data.VisitorParkingSpace));
                cmd.Parameters.Add(new SqlParameter("@VolunteeringOpportunies", data.VolunteeringOpportunies));
                cmd.ExecuteNonQuery();
            }
            return true;
        }
        #endregion
        #region[ByID]
        public List<Entity.PremiseInfor> GetById(string id)
        {
            List<Entity.PremiseInfor> lst = new List<Entity.PremiseInfor>();
            using (SqlCommand cmd = new SqlCommand("sp_Premises_GetID0", connect()))
            {
                Entity.PremiseInfor obj = new Entity.PremiseInfor();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@PremiseID", id));
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        lst.Add(obj.MappingEntity(dr));
                    }
                }
                dr.Close();
                obj = null;
            }
            return lst;
        }
        #endregion
        #region[ByName]
        public List<Entity.PremiseInfor> GetByName(string name)
        {
            List<Entity.PremiseInfor> lst = new List<Entity.PremiseInfor>();
            using (SqlCommand cmd = new SqlCommand("sp_Premises_GetName", connect()))
            {
                Entity.PremiseInfor obj = new Entity.PremiseInfor();
                cmd.CommandType = CommandType.StoredProcedure;
                cmd.Parameters.Add(new SqlParameter("@LocalName", name));
                SqlDataReader dr = cmd.ExecuteReader();
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        lst.Add(obj.MappingEntity(dr));
                    }
                }
                dr.Close();
                obj = null;
            }
            return lst;
        }
        #endregion
    }
}